Skip to content

Adding Cors handler to http request handler in netty server#756

Merged
rhernandez35 merged 11 commits into
smithy-lang:mainfrom
Groupie-Ticket:main
Jun 12, 2025
Merged

Adding Cors handler to http request handler in netty server#756
rhernandez35 merged 11 commits into
smithy-lang:mainfrom
Groupie-Ticket:main

Conversation

@dpacheco-groupieticket

Copy link
Copy Markdown
Contributor

Issue #737

Description

Netty service

This PR contains a new handler to respond with require headers when smithy.api#cors trait is set in the service.

The CorsHandler supports the case of having multiple origins, when the origin value contains multiple origins separated by commas it will check against the origin in attached in the request.

Json Serializer Test fix.

The testPrettyPrinting() test fails due to differences in line endings between operating systems. Windows uses \r\n (CRLF), while Unix-based systems (Linux/macOS) use \n (LF). The expected string, defined in a Java text block, contains Unix-style line endings (\n), but the actual output (result) contains Windows-style line endings (\r\n), causing the assertion to mismatch despite identical content. To ensure consistent behavior across platforms, we normalize line endings by removing \r before comparison or use System.lineSeparator() for OS-agnostic formatting.

Test

No unit tests are configure for the netty-server subpackage. I manually tested from an external project and the requests returns the expected headers.

@rhernandez35

Copy link
Copy Markdown
Collaborator

Thank you for the PR!

Comment thread server/server-core/build.gradle.kts Outdated
Comment on lines +53 to +54
var corsTrait = job.operation().getApiOperation()
.service()

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
var corsTrait = job.operation().getApiOperation()
.service()
var corsTrait = job.operation()
.getApiOperation()
.service()

@rhernandez35

Copy link
Copy Markdown
Collaborator

Can you run ./gradlew spotlessApply and push the changes?

@rhernandez35
rhernandez35 enabled auto-merge (rebase) June 12, 2025 00:40
@rhernandez35
rhernandez35 merged commit d928df3 into smithy-lang:main Jun 12, 2025
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants